//
//  CommunitySegCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/22.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "CommunitySegCell.h"

static CGFloat CellScaleValueMax = 1.0f;

@interface CommunitySegCell ()

@property (nonatomic, assign) BOOL isSelected;


@end

@implementation CommunitySegCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

//设置布局
- (void)layoutSubviews {
    [super layoutSubviews];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.bottomLine pp_clipCorners:UIRectCornerAllCorners radius:self.bottomLine.frame.size.height/2];
    });

}

//通过此父类方法配置cell是否被选中
- (void)configCellOfSelected:(BOOL)selected {
    [super configCellOfSelected:selected];
    
    self.isSelected = selected;
        
    if (selected) {
        self.bottomLine.hidden = NO;
        self.transform = CGAffineTransformMakeScale(CellScaleValueMax, CellScaleValueMax);
    }else {
        self.bottomLine.hidden = YES;
        self.transform = CGAffineTransformIdentity;
    }
    
    if ([self.segTitle isEqualToString:@"Ting说"]) {
        if (self.isSelected) {
            [self.bgImage setImage:[UIImage imageNamed:@"ting_sel"]];
        }else {
            [self.bgImage setImage:[UIImage imageNamed:@"ting_nor"]];
        }
    } else {
        if (self.isSelected) {
            [self.bgImage setImage:[UIImage imageNamed:@"wed_sel"]];
        }else {
            [self.bgImage setImage:[UIImage imageNamed:@"wed_nor"]];
        }
    }
}

- (void)fillWithTitle:(NSString *)title {
    
    self.segTitle = title;
}

//通过此父类方法配置cell动画 progress0~1
- (void)showAnimationOfProgress:(CGFloat)progress type:(XLPageTitleCellAnimationType)type {
    [super showAnimationOfProgress:progress type:type];
    //动画包括颜色渐变 缩放
//    if (type == XLPageTitleCellAnimationTypeSelected) {
//        //第一步 颜色渐变
//        UIColor *newColor = [XLPageViewControllerUtil colorTransformFrom:self.config.titleSelectedColor to:self.config.titleNormalColor progress:progress];
//        [self updateSubviewsColor:newColor];
//        //第二步 缩放 逐渐变小
//        CGFloat scale = (1 - progress)*(CellScaleValueMax - 1);
//        self.transform = CGAffineTransformMakeScale(1 + scale, 1 + scale);
//    }else if (type == XLPageTitleCellAnimationTypeWillSelected){
//        //第一步 颜色渐变
//        UIColor *newColor = [XLPageViewControllerUtil colorTransformFrom:self.config.titleNormalColor to:self.config.titleSelectedColor progress:progress];
//        [self updateSubviewsColor:newColor];
//
//        //第二步 缩放 逐渐变大
//        CGFloat scale = progress*(CellScaleValueMax - 1);
//        self.transform = CGAffineTransformMakeScale(1 + scale, 1 + scale);
//    }
}

- (void)updateSubviewsColor:(UIColor *)color {
//    self.mainTitle.textColor = color;
//    self.subTitle.textColor = color;
}

@end
